<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta charset="UTF-8">
	<title>登录</title>
</head>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/normalize.css">
<style type="text/css">
/*.doudou{color:red;}
.doudou span:not(:last-child){color:blue;}
.doudou span{color:green;}
.tiancai{ color:orange;}*/
</style>
<body>
	<div class="loginbg">
		<div class="login_title">Smart Outdoor Service</div>
		<div class="login">
			<form action="" id="registerForm">
				<div class="loginbox">
					<span>账号：</span><span class="fr usererr"> </span>
					<input type="text" name="userName" class="confirm" placeholder="请输入邮箱账号">
				</div>
				<div class="loginbox">
					<span>密码：</span><span class="fr pwderr"> </span>
					<input type="password" name="password" class="confirm" id="password"  placeholder="请输入账号密码">
				</div>
				<div class="agree clearfix">
					<label>
						<input type="checkbox">
						<span>我同意<a class="login_blue" href="####">隐私协议</a>和<a class="login_blue" href="#####">服务声明</a></span>
					</label>
					<label>
						<input type="checkbox">
						<span>记住账号</span>
					</label>
				</div>
				<a id="login" class="a_btn loginbtn">登录</a>
				<a class="forget login_blue" href="email.html">忘记密码？</a>
			</form>
		<!-- 	<div id="doudou">
				豆奶自称<span class="ziji">自己</span>为<span class="tiancai">天才</span>。s
			</div> -->
		</div>
		
	</div>
</body>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/ajax-information.js"></script>
<script type="text/javascript">
//getData方法,url,SignIn,getData方法在ajax-information中，用于ajax请求数据获取
var url="http://47.94.196.223:810";
var ajaxUrl=url;
var SignInUrl=SignIn;
var token="";
var saveToken=function(res,data){
	if (res && res.accessToken && res.errorCode && res.errorCode == '0000000') {
		sessionStorage.setItem('token',res.accessToken);
		sessionStorage.setItem('username',data.username);
		// sessionStorage.setItem('user',data.user);
		window.location.href='product.html';
	}
};
// 登陆
$('#login').on('click',function () {
	var username= $("#registerForm input[name='userName").val();
	var password= $("#registerForm input[name='password").val();
	var userData={
		username:username,
		password:password
	};
	console.log();
	if ($('.agree label:first-child input').is(':checked')) {
		getData('post',ajaxUrl,SignInUrl,userData,saveToken);
	}else{
		alert('请同意隐私协议和服务声明')
	}
	
});
// var strategies = {
// 	isNonEmpty:function(value,errorMsg){
// 		if(!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(value)){
// 			return errorMsg;
// 		}
// 	},
// 	Len:function(value,errorMsg){
// 		if(!/^\w{6,23}$/.test(value)){
// 			return errorMsg;
// 		}
// 	},

// };
// //执行
// var todoFunc = function(userInf){
// 	var validator = new Validator();
// 	//*****添加校验规则******//
// 	if(userInf=='userName'){
// 		validator.add(registerForm.userName,'isNonEmpty','账号格式不正确！');
// 	}else if(userInf=='password'){
// 		validator.add(registerForm.password,'Len','密码不正确');
// 	}
// 	//收集报错信息
// 	var errorMsg = validator.start();
// 	return errorMsg;
// }
// var registerForm = document.getElementById('registerForm');

// $("input[name='userName']").blur(function(){
// 	var errorMsg = todoFunc('userName');
// 	if(errorMsg){
// 		$(".loginbox .usererr").html(errorMsg);
// 		return false;
// 	}
// });
// $("input[name='userName']").focus(function(){
// 	$(".loginbox .usererr").html("");
// });
// $("input[name='password']").blur(function(){
// 	var errorMsg = todoFunc('password');
// 	if(errorMsg){
// 		$(".loginbox .pwderr").html(errorMsg);
// 		return false;
// 	}
// });
// $("input[name='userName']").focus(function(){
// 	$(".loginbox .usererr").html("");
// });
// var Validator = function(){
// 	this.cache = [];
// };
// Validator.prototype.add = function(dom,rule,errorMsg){
// 	var arr = rule.split(":");
// 	//这块是重点
// 	this.cache.push(function(){
// 	//拿出策略字串备用
// 	var strategy = arr.shift();
// 	//拼接形参
// 	//将dom值放在数组头一个
// 	arr.unshift(dom.value);
// 	//报错信息放在数组最后一个
// 	arr.push(errorMsg);
// 	//apply的妙手回春
// 	return strategies[strategy].apply(dom,arr);
// });
// };
// Validator.prototype.start = function(){
// 	for(var i=0;i<this.cache.length;i++){
// 		var msg = this.cache[i]();
// 		if(msg)
// 			return msg;
// 	}
// };
</script>
</html>